module SOD
  
  class FootprintObserver < Sketchup::EntityObserver
    
    def onChangeEntity(entity)
      self.checkOrientation(entity)
      pts = []
      loop = entity.outer_loop
      return if not loop
      
      loop.vertices.each { |p| pts << p.position }
      Plugin.model.sketchInfoContainer.footprintPoints = pts
      Plugin.model.sketchInfoContainer.update # works as long as footprint is defined by 4 points!
      
      Plugin.dialogManager.update(StructureGeneratorInterface)
      
    end
    
    def onEraseEntity(entity)
      puts "Footprint deleted"
      
      Plugin.model.sketchInfoContainer.update
      Plugin.dialogManager.update(StructureGeneratorInterface)
    end
    
    def checkOrientation(face)
      if face.normal.z < 0
        face.reverse! 
        puts "reversed"
      end
    end
    
  end
  
end
